<%@ include file="/WEB-INF/jsp/struts/taglibs.jsp" %>

<c:if test="${not empty param.successUrl}">
<script language=javascript src="js/common.js"></script>
<script language="javascript">
<!--
/**
 *  Check page number is validity.
 */
function checkPageNum(oPageIndex, pageNumValue, oldPageNum, pageCount) {
    if (pageNumValue=="") {
        alert("<bean:message bundle='alertRes' key='GW.pagination.prompt1'/>");
        oPageIndex.focus();
        return false;
    }
    if (! checkStringIsInteger(pageNumValue)) {
        alert("<bean:message bundle='alertRes' key='GW.pagination.prompt2'/>");
        oPageIndex.focus();
        return false;
    }
    if (parseInt(pageNumValue) > parseInt(pageCount)) {
        alert("<bean:message bundle='alertRes' key='GW.pagination.prompt3'/>");
        oPageIndex.focus();
        return false;
    }
    if (parseInt(pageNumValue) < 1) {
        alert("<bean:message bundle='alertRes' key='GW.pagination.prompt4'/>");
        oPageIndex.focus();
        return false;
    }
    if (parseInt(pageNumValue) == parseInt(oldPageNum)) {
        return false;
    }
    return true;
}

function gopage(pageNumValue) {
    var oForm = document.getElementById("chgPageForm");
    var oPageIndex=document.getElementById("pageIndex");
    if (! checkPageNum(oPageIndex, trim(pageNumValue), oForm.pageNum.value, oForm.pageCount.value)) return;

    oForm.pageNum.value=trim(pageNumValue);
    oForm.submit();
}
//-->
</script>
    <html:form action="/changePage" styleId="chgPageForm">
      <html:hidden property="pageNum" value="${param.pageNum}"/>
      <html:hidden property="oldPageNum" value="${param.pageNum}"/>
      <html:hidden property="pageCount" value="${param.pageCount}"/>
      <html:hidden property="inputUrl" value="${param.inputUrl}"/>
      <html:hidden property="successUrl" value="${param.successUrl}"/>
    </html:form>
    <html:errors/>
</c:if>

<table width="100%" border="0" align="center" cellpadding="2" cellspacing="1" class="tableborder">
  <tr valign="middle" class="tablefooter">
    <td width="100%" align=right class="table-link">
      <table  border="0" align="right" cellpadding="0" cellspacing="0">
        <tr>
          <td align="right" nowrap="nowrap" class="table-link">
            <div align="right">
              <c:choose>
                <c:when test="${param.pageNum <= 1}">
                  <bean:message key="gw.pagination.first"/>&nbsp;|&nbsp;
                  <bean:message key="gw.pagination.previous"/>&nbsp;|&nbsp;
                </c:when>
                <c:otherwise>
                  <a href="javascript:gopage('1');"><bean:message key="gw.pagination.first"/></a>&nbsp;|&nbsp;
                  <a href="javascript:gopage('${param.pageNum - 1}');"><bean:message key="gw.pagination.previous"/></a>&nbsp;|&nbsp;
                </c:otherwise>
              </c:choose>
              <c:choose>
                <c:when test="${fn:length(param.pageNum)>fn:length(param.pageCount) or (fn:length(param.pageNum)==fn:length(param.pageCount) and param.pageNum>=param.pageCount)}">
                  <bean:message key="gw.pagination.next"/>&nbsp;|&nbsp;
                  <bean:message key="gw.pagination.last"/>&nbsp;
                </c:when>
                <c:otherwise>
                  <a href="javascript:gopage('${param.pageNum + 1}');"><bean:message key="gw.pagination.next"/></a>&nbsp;|&nbsp;
                  <a href="javascript:gopage('${param.pageCount}');"><bean:message key="gw.pagination.last"/></a>&nbsp;
                </c:otherwise>
              </c:choose>
              &nbsp;<bean:message key="gw.pagination.page"/>:&nbsp;
              <c:choose>
                <c:when test="${param.pageCount=='0'}">${param.pageCount}</c:when>
                <c:otherwise>${param.pageNum}</c:otherwise>
              </c:choose>
              <bean:message key="gw.pagination.of"/>&nbsp;${param.pageCount}&nbsp;
              <input type="text" size="3" id="pageIndex" value="" onkeydown="if(event.keyCode == 13) gopage(document.getElementById('pageIndex').value);"/>&nbsp;
            </div>
          </td>
          <td width="36" align="right" nowrap="nowrap" class="table-link">
            <a href="javascript:gopage(document.getElementById('pageIndex').value);" class="btn" style="margin-top: 0px;">
              <span>Go</span>
            </a>
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>
